package com.example.casper.Experiment2024.data;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;

public class Bomb {
    private int x;
    public int y;
    private int size, speed;
    private int screenWidth, screenHeight;
    private Paint paint;

    public Bomb(int screenWidth, int screenHeight) {
        this.screenWidth = screenWidth;
        this.screenHeight = screenHeight;
        size = 50;
        speed = 10;
        resetPosition();

        paint = new Paint();
        paint.setColor(Color.RED);
    }

    public void update() {
        y += speed;
    }

    public void draw(Canvas canvas, Paint paint) {
        canvas.drawCircle(x, y, size, this.paint);
    }

    public void resetPosition() {
        x = (int) (Math.random() * screenWidth);
        y = -size;
        speed += 2; // 随时间增加速度
    }

    public boolean isColliding(Submarine submarine) {
        Rect submarineBounds = submarine.getBounds();
        return Rect.intersects(submarineBounds, new Rect(x - size, y - size, x + size, y + size));
    }
}
